package com.itheima.servletConfig;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Demo8Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取当前servlet配置对象
		ServletConfig sc = getServletConfig();
		//获取servlet名称
		String servletName = sc.getServletName();
		System.out.println("servletName:"+servletName);
		//获取servlet的初始化参数
		String db = sc.getInitParameter("db");
		System.out.println("db:"+db);
		//获取servlet所有的初始化参数的名称
		Enumeration<String> initParameterNames = sc.getInitParameterNames();
		while (initParameterNames.hasMoreElements()) {
			String string = (String) initParameterNames.nextElement();
			System.out.println(string+":"+sc.getInitParameter(string));
			
		}
		//获取上下文(全局管理者)
		ServletContext servletContext = sc.getServletContext();
		System.out.println(servletContext);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
